package cn.e4j.modular.crm.controller;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.core.shiro.ShiroKit;
import cn.e4j.core.shiro.ShiroUser;
import cn.e4j.core.util.LangUtils;
import cn.e4j.modular.common.service.SysAuthorityService;
import cn.e4j.modular.crm.entity.Gwai760;
import cn.e4j.modular.crm.service.impl.Gwai760ServiceImpl;
import cn.e4j.modular.crm.service.impl.Gwai780ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 退货确认单管理
 * Created by shixc on 2019-3-8
 */
@Controller
@RequestMapping("/crm/gwai780")
public class Gwai780Controller extends BaseController {

    @Autowired
    private Gwai760ServiceImpl gwai760Service;

    @Autowired
    private Gwai780ServiceImpl gwai780Service;

    @Autowired
    public SysAuthorityService sysAuthorityService;

    /**
     * 跳转商品经营范围管理页面
     */
    @RequiresPermissions("crm:gwai780:init")
    @RequestMapping(value = {"", "init"})
    public String index() {
        return "/pc/crm/gwai780.html";
    }

    /**
     * 查询商品经营范围信息列表
     */
    @RequestMapping("/getList")
    @RequiresPermissions("crm:gwai780:init")
    @ResponseBody
    public ResponseData getList(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        Dto inDto = dtoWapper.getDto();
//        //客户权限
//        inDto.put("CUSTOMERS", sysAuthorityService.getCustomersAuthority(inDto));
        List<Map<String, Object>> result = gwai780Service.getList(page, inDto);
        return new PageReData(page, result);
    }

    /**
     * 批量确认数据
     */
    @RequestMapping("/refund")
    @RequiresPermissions("crm:gwai780:init")
    @ResponseBody
    public ResponseData refund(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<Gwai760> gwdaTList = inDto.getReqList(Gwai760.class);
        Dto info = this.gwai780Service.getUser(ShiroKit.getUser().getID());
        gwai760Service.refund(gwdaTList, info);
        return SUCCESS_TIP;
    }

    @RequestMapping("/getDetail")
    @RequiresPermissions("crm:gwai780:init")
    @ResponseBody
    public ResponseData getGwdb(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<Dto> list = gwai780Service.getDeatil(inDto);
        return new SuccessResponseData(list);
    }


    /**
     * 批量审核数据
     */
    @RequestMapping("/check")
    @RequiresPermissions("crm:gwai780:init")
    @ResponseBody
    public ResponseData check(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        Dto info = this.gwai780Service.getUser(ShiroKit.getUser().getID());
        gwai780Service.check(inDto, info);
        return SUCCESS_TIP;
    }

    /**
     * 获取当前用户的类型
     */
    @RequestMapping("/getType")
    @RequiresPermissions("crm:gwai780:init")
    @ResponseBody
    public ResponseData getType() {
        ShiroUser shiroUser = ShiroKit.getUser();
        Dto inDto = Dtos.newDto();
        inDto.put("TYPE", shiroUser.getTYPE());
        return new SuccessResponseData(inDto);
    }
}
